package com.nzy.ssm.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.nzy.ssm.base.BaseController;
import com.nzy.ssm.entity.Manage;
import com.nzy.ssm.service.IManageService;
import com.nzy.ssm.util.Constants;
import com.nzy.ssm.util.ResultUtil;

@Controller
@RequestMapping("/manage")
public class ManageController extends BaseController {

	@Autowired
	private IManageService manageService;
	
	@RequestMapping("/login")
	public String toLogin() {
		return "/login/mLogin";
	}
	
	@RequestMapping("/index")
	public String toIndex() {
		return "/login/mIndex";
	}
	
	
	@RequestMapping("/adminLogin")
	@ResponseBody
	public ResultUtil login(Manage manage,HttpServletRequest request) {
		Manage byEntity = manageService.getByEntity(manage);
		if (byEntity != null) {
			// 1、把manage对象存到session中
			request.getSession().setAttribute(Constants.MANAGE, byEntity);
			// 2、返回登录成功给前端
			return ResultUtil.ok("登录成功");
		}
		// 返回提示登录失败
		return ResultUtil.error("登录失败");
	}
	
	
	
}
